package com.spa.interfaces.admin;

import com.spa.application.command.admin.ShopUserAddCommand;
import com.spa.application.command.admin.ShopUserDelCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.ShopUserDTO;
import com.spa.application.dto.admin.ShopUserExportDTO;
import com.spa.application.query.admin.ShopUserQuery;
import com.spa.application.service.admin.ShopUserApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/admin/shop/user")
public class ShopUserController extends BaseController {

    @Autowired
    private ShopUserApplicationService shopUserApplicationService;

    @PostMapping("add")
    public ResponseMessage add(@Validated @RequestBody ShopUserAddCommand command) {
        shopUserApplicationService.add(command);
        return responseHelper.success();
    }

    @PostMapping("del")
    public ResponseMessage del(@Validated @RequestBody ShopUserDelCommand command) {
        shopUserApplicationService.del(command);
        return responseHelper.success();
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<ShopUserDTO>> page(@RequestBody ShopUserQuery query) {
        return responseHelper.success(shopUserApplicationService.page(query));
    }

    @PostMapping("export")
    public void exportShopUser(HttpServletResponse response, @RequestBody ShopUserQuery query) throws Exception {
        exportQueryResult(response, shopUserApplicationService.list(query), "门店账号列表", "门店账号列表", ShopUserExportDTO.class);
    }

}
